package org.zk.dubbo_provider.service.impl;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.zk.dubbo_provider.dao.SubjectMapper;
import org.zk.entity.Subject;
import org.zk.entity.Type;
import org.zk.service.SubjectService;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 科目表 服务实现类
 * </p>
 *
 * @author Alicelonely
 * @since 2019-12-11
 */
@Service(timeout = 10000)
public class SubjectServiceImpl   implements SubjectService {

    @Resource
    private SubjectMapper subjectMapper;

    /**
     * 根据typeId查询subject，用于首页全部课程的查询
     * @param map
     * @return
     */
    @Override
    public List<Subject> getSubjectByTypeId(Map map) {
        return subjectMapper.getSubjectByTypeId(map);
    }

    @Override
    public List<Subject> getSubjectByTid(int typeId) {
        return subjectMapper.getSubjectByTid(typeId);
    }

    @Override
    public PageInfo getAllSubjectsPage(Map map) {
        PageInfo<Subject> pageInfo;
        int pageSize=Integer.parseInt(String.valueOf(map.get("pageSize")));
        int pageNum=Integer.parseInt(String.valueOf(map.get("pageNum")));
        PageHelper.startPage(pageNum,pageSize);
        try {
           List<Subject> list= subjectMapper.getAllSubjectPages(map);
            pageInfo = new PageInfo<Subject>(list,pageSize);

        }finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return pageInfo;
    }

    @Override
    public int insertSubject(Map map) {
        return subjectMapper.insertSubject(map);
    }

    @Override
    public int delSubjectCourseBySid(int id) {
        return subjectMapper.delSubjectCourseBySid(id);
    }

    @Override
    public int updateSubjectByTid(Map map) {
        return subjectMapper.updateSubjectByTid(map);
    }

    @Override
    public String getSubjectByid(int id) {
       return subjectMapper.getSubjectByid(id);
    }


    public SubjectMapper getSubjectMapper() {
        return subjectMapper;
    }

    public void setSubjectMapper(SubjectMapper subjectMapper) {
        this.subjectMapper = subjectMapper;
    }
}
